#ifndef CCLIENTNETENGINE_H
#define CCLIENTNETENGINE_H

#include <QObject>
#include <QAbstractSocket>
#include <QMutex>
#include <QQueue>

class CNetMsg;

class CClientNetEngine : public QObject
{
	Q_OBJECT
public:
	CClientNetEngine(QAbstractSocket *pSock);

	int getMsgCount();
	CNetMsg *getMessage();

public slots:
	// tell the FSM to connect to the server:
	// TODO - need better names to differentiate the different stage connections.
	void connectToServer(QString strUsername, QString strPassowrdHash);

signals:
	// this is emitted when the first-stage connection is complete:
	// todo - can we pass the message object directly? or do we just send the relevant
	// bits of information.
	void newMessage();

	// this signal is emitted when the communication protocol breaks down for some reason:
	void commsError(QString);

private:
	QAbstractSocket *m_pSocket;


	void queueMessage(CNetMsg*);
	QMutex m_queueMutex;
	QQueue<CNetMsg*> m_messages;
};

#endif // CCLIENTNETENGINE_H
